﻿using IMPL.Controls;
using IMPL.Helpers;
using IMPL.Reused;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms.Integration;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace IMPL
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private ImagePanelContainer imagePanelContainer;

        public MainWindow()
        {
            InitializeComponent();
            imagePanelContainer = new ImagePanelContainer(MainPanel);
        }

        private void CreateHistogram(FastBitmap bmp)
        {
            var formsHost = new WindowsFormsHost();
            var histogram = new Histogram(bmp);
            histogram.Build();
            formsHost.Child = histogram;
            HistogramPanel.Children.Add(formsHost);
        }

        #region Menu
        private void Open_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Title = "Select a picture";
            dialog.Filter = "All supported graphics|*.jpg;*.jpeg;*.png;*.tif;*.bmp|"
                + "JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|"
                + "Portable Network Graphic (*.png)|*.png";
            if (dialog.ShowDialog() == true)
            {
                var bitmap = new BitmapImage(new Uri(dialog.FileName));
                this.imagePanelContainer.AddPanel(bitmap);
                CreateHistogram(new FastBitmap(bitmap));
            }
        }

        private void MetodaSrednich_Click(object sender, RoutedEventArgs e)
        {
            this.imagePanelContainer.ApplyOperation(Lab1.Metody.Srednich);
        }

        private void MetodaLosowa_Click(object sender, RoutedEventArgs e)
        {
            this.imagePanelContainer.ApplyOperation(Lab1.Metody.Losowa);
        }

        private void MetodaSasiedztwa_Click(object sender, RoutedEventArgs e)
        {
            this.imagePanelContainer.ApplyOperation(Lab1.Metody.Sasiedztwa);
        }
        #endregion
    }
}
